/**
 * tjftp -- A simple FTP server, using the ANSI C
 * Copyright (C) 2011  degui.chen <degui.chen@qq.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include <string.h>
#include <stdlib.h>
#include "cmd.h"
#include "../sesstion.h"
#include "../lib/sockets.h"
#include "../lib/port.h"
int tj_cmd_list(int accept_fd, char* request, char* response) {
	request = request + strlen("LIST ");
	tj_string_trim(request);
	PSesstion sesstion = tj_sesstion_get(accept_fd);
	char* dir = sesstion->pwd;
	if (sesstion->is_port_mode) {
		char dirpath[255] = { '\0' };
		sprintf(dirpath, "%s%s", sesstion->root_path, sesstion->pwd);
		char info[1024] = { '\0' };
		ftp_list(dirpath, info);
		tj_port_send_message(sesstion->port_address, info);
	}
	//@todo pasv 模式的请求
	char info2[] = "150 Opening UTF-8 mode data connection for /bin/ls.\r\n226-Maximum disk quota limited to 500000 kBytes\r\n    Used disk quota 5148 kBytes, available 494851 kBytes\r\n";
	send(accept_fd, info2, strlen(info2) + 1, 0);

	strcpy(response, "226 Transfer complete.");
	return strlen(response);
}
